tg-me.com/python_codes/8
Last Update:
5. Lists
>>> list=[8,0,5,1]
>>> list
[8, 0, 5, 1]
>>> len(list)
4
>>> list_2=['string',8086,'p']
>>> list_2
['string', 8086, 'p']
>>> len(list_2)
3
Indexing and Slicing
>>> list=['one','ox','ok']
>>> list[0]
'one'
>>> list[1:]
['ox', 'ok']
>>> list[:2]
['one', 'ox']
>>> list[-1]
'ok'
>>> list[::-1]
['ok', 'ox', 'one']
>>> list+[235]
['one', 'ox', 'ok', 235]
>>> list*2
['one', 'ox', 'ok', 'one', 'ox', 'ok']
Basic List Methods
>>> list=[4,0,1,3]
>>> list.append("new")
>>> list
[4, 0, 1, 3, 'new']
>>> list.pop(0)
4
>>> list
[0, 1, 3, 'new']
>>> list.reverse()
>>> list
['new', 3, 1, 0]
Nesting Lists
>>> lst_1=[1,2,3]
>>> lst_2=[4,5,6]
>>> lst_3=[7,8,9]
>>> matrix = [lst_1,lst_2,lst_3]
>>> matrix
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> matrix[1]
[4, 5, 6]
>>> matrix[0][1]
2
@python_codes
BY Python Codes
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/python_codes/8